package com.wtwd.campus.send;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.*;
import com.wtwd.campus.utils.UnicodeUtil;
import org.apache.commons.lang.StringUtils;

import java.util.LinkedHashMap;

/**
 * @Author: ldaoliang
 * @DateTime: 2022/1/10 14:45
 * @Description:
 */
public class VcomNoticeMessageSender implements Sender{
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        MqVcomMessage mqVcomMessage = (MqVcomMessage) mqMessage.getObject();
        String imei = mqVcomMessage.getImei();
        String commandNumber = mqVcomMessage.getCommandNumber();
        LinkedHashMap hashMap = (LinkedHashMap) mqVcomMessage.getCommandContent();
        ObjectMapper objectMapper = new ObjectMapper();
        VcomNoticeMessage vcomNoticeMessage = objectMapper.convertValue(hashMap,VcomNoticeMessage.class);
        StringBuilder sb = new StringBuilder("*WT,");
        sb.append(imei).append(",NOTICEMESSAGE,").append(commandNumber).append(",");
        sb.append(StringUtils.isBlank(vcomNoticeMessage.getSenderName()) ? "" : UnicodeUtil.gbEncoding(vcomNoticeMessage.getSenderName())).append(",");
        sb.append(StringUtils.isBlank(vcomNoticeMessage.getMessage()) ? "" : UnicodeUtil.gbEncoding(vcomNoticeMessage.getMessage())).append(",");
        sb.append(vcomNoticeMessage.getShowType()).append(",");
        sb.append(vcomNoticeMessage.getPlayTimes()).append(",");
        sb.append(vcomNoticeMessage.getShakeFlg()).append(",");
        sb.append(vcomNoticeMessage.getRingFlg()).append(",");
        sb.append(vcomNoticeMessage.getFlashScreenFlg());
        sb.append("#");
        Command command=new Command();
        command.setImei(imei);
        command.setCommandNumber(commandNumber);
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setContent(sb.toString());
        command.setCmd(Constants.VCOM_NOTICE_MESSAGE);
        return command;
    }
}
